/**
* $Id$
* utility class for parsing configuration files
* features:
*	1) support comment line, start with "#" or "//"
*   2) support variable
*	3) support multiple configuration files
*/

#ifndef __D_CONFIG_H__
#define __D_CONFIG_H__

#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
using namespace std;

namespace d_utils
{

class Config{
public:
	Config();
	Config(const string &fileName);
	virtual ~Config();
	string operator [](const string &key);
	string get(const string &key);
	string get(const string &key, const string &def);
	int getInt(const string &key);
	int getInt(const string &key, int def);
	float getFloat(const string &key);
	float getFloat(const string &key, float def);
	bool isInitialized();
	int addConfFile(const string &fileName);
	void getAllKeys(vector<string> &keys);
	void addConfigItem(const string &key, const string &value);
public: 
	static const string DELIMITERS;
private:
	map<string, string> confTable;
	map<string, string> varTable;
	bool initialized;
protected:
	//return 0 means everyting is OK
	virtual int parseFile(const string &fileName);
	
	virtual void replaceVariable(string &value);

	//return 0 means everything is OK
	virtual int separateString(const string &src, string &key, string &value);
};

}
#endif //__CONFIG_H__
